<extend name="Index/index" />
<block name="Main content">
    <!-- <div class="container"> -->
        <!-- <h1><span class="glyphicon glyphicon-user"></span> <{$title}></h1> -->
        <div style="padding:3px"></div>

        <div class="mt20">
            <a href="<{:U('User/index')}>" class="btn btn-info">首页</a>

            <a href="<{:U('User/add')}>" class="btn btn-success">添加</a>

            <a href="<{:U('User/index')}>" class="btn btn-primary col-md-offset-1">全部</a>

            <a href="<{:U('User/index',array('condition'=>1))}>" class="btn btn-danger ">已禁用</a>
        </div>
        <div style="padding:3px"></div>
       

        <block name="main">
        <table class="table table-hover">
            <tr class="success">
                <th>ID</th>
                <th>姓名</th>
                <th>性别</th>
                <th>注册时间</th>
                <th>电话</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            <volist name="list" id="v">
            <tr>
                <td><{$v.id}></td>
                <td><{$v.name}></td>
                 <td>
                    <if condition="$v.sex eq '0'">女
                    <elseif condition="$v.sex eq '1'" />男
                    <else/>保密</if>
                </td>
                <td><{$v.regtime}></td>
                <td><{$v.tel}></td>
                <td><if condition="$v.denied eq '0' "><button class="btn btn-danger deny" userid="<{$v.id}>"><span class="glyphicon glyphicon-remove"></span></button>
                <else/>
                <button class="btn btn-success deny" userid="<{$v.id}>"><span class="glyphicon glyphicon-ok"></span></button></if>
                </td>
                <td class="col-md-2">
                    <a href="<{:U('User/edit',array('id'=>$v['id']))}>" class="btn btn-sm btn-primary">编辑</a>
                    <!-- <button class="btn btn-sm btn-danger del" userid="<{$v.id}>">删除</button> -->
                </td>
            </tr>

            </volist>
        </table>
        <div><{$page}></div>
        </block>
    
</block>

<block name="myjs">
    <script>



        $(document).ready(function(){
            // console.log(1);
            var deny = $('button.deny');
            for (var i = 0; i < deny.length; i++) {
                $(deny[i]).click(function(){
                    console.log($(this));
                    var userid = $(this).attr('userid');
                    // 判断button的状态
                    if ($(this).html() == '<span class="glyphicon glyphicon-ok"></span>') {
                        $.ajax({
                            type: 'get',
                            url: "<{:U('User/denied')}>",
                              data: 'id=' + $(this).attr('userid')+'&denied=1'+'&table=user',
                        });
                        $(this).html('<span class="glyphicon glyphicon-remove">').removeClass('btn-success').addClass('btn-danger');
                    } else {
                        $.ajax({
                            type: 'get',
                            url: "<{:U('User/denied')}>",
                            data: 'id=' + $(this).attr('userid')+'&denied=0'+'&table=user',
                        });
                        $(this).html('<span class="glyphicon glyphicon-ok"></span>').removeClass('btn-danger').addClass('btn-success');
                    };

                                
                    return false; //阻止跳转
                });
            }; // 状态点击事件结束
            //删除的ajax
            // var dellist = $('button.del');
            //     for (var i = 0; i < dellist.length; i++) {
            //         $(dellist[i]).click(function(){
            //             // console.log($(this));
            //             var userid = $(this).attr('userid');
            //             if (confirm('您确认删除id为'+userid+'的用户吗')) {
            //             $(this).parent().parent().remove();
            //             开启ajxa
            //             $.ajax({
                            
            //             });
            //             };
                        
            //         })
            //     };

        });
    </script>
</block>